package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueNoticeDao;
import com.prs.crm.domain.doc.IssueNotice;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Notice;
import com.prs.crm.service.doc.IssueNoticeService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.NoticeService;

public class IssueNoticeServiceImpl extends BaseServiceImpl<IssueNotice,IssueNoticeDao> implements IssueNoticeService{
	private NoticeService noticeService;
	private PersonService personService;
	
	@Override
	public void submitIssueNotice(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Notice> notices = this.getNoticeService().getNoticeByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		
		for(Person person : persons) {
			for(Notice notice : notices) {
				IssueNotice issue = new IssueNotice();
				issue.setReceivePerson(person);
				issue.setNotice(notice);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}

	public NoticeService getNoticeService() {
		return noticeService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	@Override
	public Collection<IssueNotice> getValidIssueNotice(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueNotice(person);
	}

}
